/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2025-03-11
 * Time: 23:10
 */
public class Main {
    public int lengthOfLongestSubstring(String ss) {
        char[] s = ss.toCharArray();

        int[] hash = new int[128];//用数组模拟哈希表
        int left = 0,right = 0,n = ss.length();
        int ret = 0;
        while(right < n){
            hash[s[right]]++;//进入窗口
            while (hash[s[right]] > 1){ //判断
                hash[s[left++]]--;//出窗口
            }
            ret = Math.max(ret,right-left+1);//更新结果
            right++;//让下一个字符进入窗口
        }
        return ret;
    }
}
